//
//  YXCustomNavigation.m
//  跑跑快销
//
//  Created by 杨潇 on 14-3-11.
//  Copyright (c) 2014年 YX. All rights reserved.
//

#import "YXCustomNavigation.h"

@implementation YXCustomNavigation
@synthesize title = _title, backBtnTitle = _backBtnTitle;
@synthesize backObj = _backObj;

- (id)initWithTitle:(NSString *)title withBackTitle:(NSString *)backTitle withObj:(UIViewController *)vc
{
    self = [super init];
    if (self) {
        // Initialization code
        int y;
        if (ISDEVICE7) {
            y = 20;
        }else{
            y = 0;
        }
        self.backObj = vc;
        self.frame = CGRectMake(0, y, 320, 62);
        UIImageView * backGroundImg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 62)];
        backGroundImg.backgroundColor = [UIColor redColor];
        [self addSubview:backGroundImg];
        if (title) {
            UIFont * titleFont = [UIFont boldSystemFontOfSize:25];
            CGSize titleSize = [title sizeWithAFont:titleFont];
            UILabel * titleLab = [[UILabel alloc] init];
            titleLab.font = titleFont;
            titleLab.text = title;
            titleLab.bounds = CGRectMake(0, 0, titleSize.width, titleSize.height);
            titleLab.center = CGPointMake(160, 20);
            [self addSubview:titleLab];
        }
        
        if (backTitle) {
            UIFont * backFont = [UIFont systemFontOfSize:13];
            CGSize backSize = [backTitle sizeWithAFont:backFont];
            UIButton * back = [UIButton buttonWithType:UIButtonTypeCustom];
            back.frame = CGRectMake(10, 5, backSize.width + 30, 30);
            [back setTitle:backTitle forState:UIControlStateNormal];
            [back addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
            [self addSubview:back];
        }
}
    return self;
}

- (void)back
{
    [self.backObj.navigationController popViewControllerAnimated:YES];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
